package com.chen.internalcommon.dto;

import com.chen.internalcommon.constant.CommonStatusEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * @author chenLiuPing
 **/
@Data
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class ResponseResult<T> {

    private int code;
    private String message;
    private T data;

    public static ResponseResult success() {
        return new ResponseResult(CommonStatusEnum.SUCCESS);
    }

    private ResponseResult(CommonStatusEnum commonStatusEnum) {
        this.code = commonStatusEnum.getCode();
        this.message = commonStatusEnum.getMessage();
    }



    public static <T> ResponseResult success(T data) {
        return success().setData(data);
    }

    public static ResponseResult fail(CommonStatusEnum commonStatusEnum) {
        return new ResponseResult(commonStatusEnum);
    }

    public static ResponseResult fail(String message) {
        return new ResponseResult(0, message, null);
    }
}
